
using System;

using System.Collections.Generic;
using UnityEngine;

public class Solution : MonoBehaviour
{

    public class TreeNode
    {
        public int val;
        public TreeNode left;
        public TreeNode right;
        public TreeNode(int x) { val = x; }
    }
    void Start()
    {
        int[] nums = { 5, 5, 6, 6, 7, 8, 1, 2, 3, 4, 5 };
        //Debug.Log(MinArray(nums));

    }
    //  动态规划/第二数学归纳法 充分利用之前的值进行推导
    // public int Fib(int n)
    // {
    //     if (n == 0) return 0;
    //     if (n == 1) return 1;
    //     int sum_1 = 0;
    //     int sum_2 = 1;
    //     int sum_last = 0;
    //     for (int i = 0; i < n - 1; i++)
    //     {
    //         sum_last = (sum_1 + sum_2) % 1000000007;
    //         sum_1 = sum_2;
    //         sum_2 = sum_last;
    //     }
    //     return sum_last;
    // }


    //我的思路：两层循环暴力破解
    //官方思路：
    public int MaxProfit(int[] prices)
    {
        int min_pri = prices.Length > 0 ? prices[0] : 0;
        int D_value = 0;

        for (int i = 0; i < prices.Length; i++)
        {
            if (min_pri > prices[i])
            {
                min_pri = prices[i];
            }
            else if (prices[i] - min_pri > D_value)
            {
                D_value = prices[i] - min_pri;
            }
        }
        return D_value;
    }
}